﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ManageBanking.Areas.Admin.Models;
namespace ManageBanking.Areas.Admin.Controllers
{
    public class LoginAdminController : Controller
    {
        //
        // GET: /Admin/LoginAdmin/
        LoginAdminModels lg = new LoginAdminModels();
        public ActionResult LoginAdmin()
        {
            return View();
        }
        public ActionResult ResolveLogin(string username, string password)
        {
            if (lg.Login_Bank2(username) == false)
            {
                Session["CheckUser"] = "Wrong Username";
                return RedirectToAction("LoginAdmin");
            }
            else if (lg.Login_Bank(username, password) == true)
                {

                    Username ac = lg.Login_Acc(username);
                    if (ac.LastLogin == null)
                    {
                        Session.Remove("CheckUser");
                        
                        DateTime dt1 = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); ;
                        Session["Admin"] = ac;
                        lg.updatelasttime(username);
                        ac.LastLogin = dt1;
                        Session["Admin"] = ac;
                        return RedirectToAction("LoginAdmin");
                    }
                   
                    else
                    {
                        Session.Remove("CheckUser");
                       

                        DateTime dt1 = ac.LastLogin.Value;

                        Session["Admin"] = ac;
                        lg.updatelasttime(username);
                        ac.LastLogin = dt1;
                        Session["Admin"] = ac;
                        return RedirectToAction("Paging", "ManageAdmin");

                    }
                }
                else
                {
                   Session["CheckUser"]="Invalid Password";
                  
                    return RedirectToAction("LoginAdmin");
                }

            }
        public ActionResult LogOut()
        {
            Session.Remove("Admin");
            return RedirectToAction("LoginAdmin");
        }
            
        
        }

    }

